﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace SwormTests.IUD
{
    public class inserts : TestBase
    {
        public inserts(DbToTest type) : base(type) { }

        class no_pk
        {
            public string name { get; set; }
        }

        class identity_pk
        {
            public int id { get; set; }
            public string name { get; set; }
        }

        [Test]
        public void can_insert_with_no_pk()
        {
            var item = new no_pk() { name = "bobby ' tables" };
            DB.Insert(item);

            var fromDB = DB.Query.Simple<no_pk>().List().Single();
            Assert.AreEqual("bobby ' tables", fromDB.name);
        }

        [Test]
        public void can_insert_identity_pk()
        {
            var item = new identity_pk() { name = "the @#$%'^ string" };
            DB.Insert(item);
            Assert.AreNotEqual(0, item.id);

            var fromDB = DB.Query.Simple<identity_pk>().List().Single();
            Assert.AreEqual("the @#$%'^ string", fromDB.name);
            Assert.AreEqual(item.id, fromDB.id);
        }
    }
}
